/**
 * 
 */
package com.kth.subtranslator.ui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.kth.subtranslator.ITranslateDriver;
import com.kth.subtranslator.TranslateEngine.Language;

/**
 * @author Kevin Thackray
 *
 */
public class TranslateDialog extends JDialog {

	public static enum Action {
		OK,
		CANCEL;
	}
	
	private final JPanel contentPanel = new JPanel();
	private JComboBox driverCombo;
	private JComboBox languageCombo;

	private Action inputValue;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			TranslateDialog dialog = new TranslateDialog();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public TranslateDialog() {
		setModalityType(ModalityType.APPLICATION_MODAL);
		setResizable(false);
		setTitle("Translate Subtitle");
		setBounds(100, 100, 282, 135);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(new GridLayout(0, 1, 0, 0));
		{
			JLabel lblLanguage = new JLabel("Translate my Subtitle to");
			contentPanel.add(lblLanguage);
		}
		{
			languageCombo = new JComboBox();
			contentPanel.add(languageCombo);
		}
		/*
		{
			JLabel lblDriver = new JLabel("Driver");
			GridBagConstraints gbc_lblDriver = new GridBagConstraints();
			gbc_lblDriver.anchor = GridBagConstraints.EAST;
			gbc_lblDriver.insets = new Insets(0, 0, 0, 5);
			gbc_lblDriver.gridx = 0;
			gbc_lblDriver.gridy = 1;
			contentPanel.add(lblDriver, gbc_lblDriver);
		}
		*/
		/*
		{
			driverCombo = new JComboBox();
			driverCombo.setRenderer( new DriverRenderer() );
			GridBagConstraints gbc_driverCombo = new GridBagConstraints();
			gbc_driverCombo.fill = GridBagConstraints.HORIZONTAL;
			gbc_driverCombo.gridx = 1;
			gbc_driverCombo.gridy = 1;
			contentPanel.add(driverCombo, gbc_driverCombo);
		}
		*/
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener( new ActionListener() {

					@Override
					public void actionPerformed(ActionEvent e) {
						setInputValue(Action.OK);
						setVisible(false);
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addActionListener( new ActionListener() {

					@Override
					public void actionPerformed(ActionEvent e) {
						setInputValue(Action.CANCEL);
						setVisible(false);
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}

	/**
	 * @return the driverCombo
	 */
//	public JComboBox getDriverCombo() {
//		return driverCombo;
//	}

	/**
	 * @return the languageCombo
	 */
	public JComboBox getLanguageCombo() {
		return languageCombo;
	}

	/**
	 * @param inputValue the inputValue to set
	 */
	private void setInputValue(Action inputValue) {
		this.inputValue = inputValue;
	}

	/**
	 * @return the inputValue
	 */
	public Action getInputValue() {
		return inputValue;
	}

}
